package cn.com.chec.en.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import cn.com.chec.en.util.PropertiesUtil;

public class DBFactory {
	private static DBFactory _instance = null;

	public static DBFactory getInstance() {
		if (_instance == null) {
			synchronized (DBFactory.class) {
				if (_instance == null) {
					_instance = new DBFactory();
				}
			}
		}
		return _instance;
	}

	public Connection getConnection() {
		Connection conn = null;
		try {
			Class.forName(PropertiesUtil.getValue("mysqlDBDriver"));
			conn = DriverManager.getConnection(
					PropertiesUtil.getValue("mysqlConnectionURL"),
					PropertiesUtil.getValue("mysqlDBUsername"),
					PropertiesUtil.getValue("mysqlDBPassword"));
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return conn;
	}

	public static void main(String[] args) throws SQLException {
		System.out.println(PropertiesUtil.getValue("mysqlDBDriver"));
		Connection conn = getInstance().getConnection();
		System.out.println(conn);
		conn.close();
	}
}